package com.safe.ly_safe.utils;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.WindowManager;

import org.json.JSONObject;

import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * @PACKAGE :com.safe.ly_safe.utils
 * @Author : HSF
 * @Time : On 2022/4/22 16:13
 * @Description : until
 */
public class MyUntil {

    public static RequestBody getRequestBody(Map<String,Object> mp){
        JSONObject jsonObject = new JSONObject(mp);
        String bodyContent = jsonObject.toString();
        RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), bodyContent);
        return body;
    }

    public static int getScreenHeight(Context context) {
        DisplayMetrics metric = new DisplayMetrics();
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        wm.getDefaultDisplay().getMetrics(metric);
        return metric.heightPixels;
    }

    public static int getScreenWidth(Context context) {
        DisplayMetrics metric = new DisplayMetrics();
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        wm.getDefaultDisplay().getMetrics(metric);
        return metric.widthPixels;
    }

    public static int dp2px(Context context, float dp) {
        float density = context.getResources().getDisplayMetrics().density;
        return (int)(dp * density + 0.5F);
    }
}
